//
//  LYRouterManager.h
//  Router
//
//  Created by 九爷 on 2021/11/1.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

FOUNDATION_EXPORT NSString * LY_EXTRA_WEB_URL_KEY;

typedef void(^LYRouteBackHandle)(id object);
typedef BOOL(^LYRouteBeforeJumpComplation)(NSDictionary *param, NSString *url);

///支持的路由文件类型
typedef NS_ENUM(NSUInteger, LYRouteFileType) {
    ///JSON格式
    LYRouteFileTypeJSON,
    ///XML格式
    LYRouteFileTypeXML,
};

@interface LYRouterManager : NSObject

/**
 @brief 路由单例

 @return LYRouter
 */
+ (instancetype)manager;

/**
 @brief 是否显示调试日志(Release下需要关闭)

 @param enable 是否打开日志
 */
+ (void)enableLog:(BOOL)enable;

/**
 *@brief 读取配置路由文件
 *
 *@param fileName 路由配置文件名
 *@param fileType 路由配置文件后缀名
 */
- (void)configRouterWithFileName:(NSString *)fileName fileType:(LYRouteFileType)fileType;

/**
 *@brief 读取配置路由文件
 *
 *@param filePath json配置文件路径
 */
- (void)configRouterWithFilePath:(NSString *)filePath;

/**
 *@brief 配置scheme白名单
 *
 *@param whiteList 白名单数组
 */
- (void)configWhiteSchemes:(NSArray<NSString *> *)whiteList;

/**
 *@brief 配置host白名单
 *
 *@param whiteList 白名单数组
 */
- (void)configWhiteHosts:(NSArray<NSString *> *)whiteList;

/**
 *@brief 配置host白名单
 *
 *@param schemes 允许重写scheme
 */
- (void)configAllowRewriteSchemes:(NSArray<NSString *> *)schemes rewriteSchemeTarget:(NSString *)targetScheme;

/**
 *@brief 配置识别http开头的跳转
 *该配置需要继承LYRouterProtocol协议
 *并在bindParameter方法中通过LY_EXTRA_WEB_URL_KEY获取url
 *
 *@param webUrl web路由地址
 */
- (void)configWebUrl:(NSString *)webUrl;

/**
 *@brief 路由跳转前置方法
 *
 *@param complation 跳转前置回调，包含路由参数和当前跳转路径
 */
- (void)bindJumpBeforeComplation:(LYRouteBeforeJumpComplation)complation;

/**
 *@brief 替换跳转路由路径
 *
 *@param newPath 新的跳转路径
 */
- (void)replaceUrlPathWithNewPath:(NSString *)newPath;

/**
 *@brief 根据URL地址获取对应Controller
 *
 *@param url URL地址
 *@return UIViewController 原生页面
 */
- (UIViewController *)controllerWithUrl:(NSString *)url;

/**
 *@brief 根据URL地址获取对应Controller
 *
 *@param url URL地址
 *@param extraParam 额外的无法通过URL地址传入的参数
 *@return UIViewController 原生页面
 */
- (UIViewController *)controllerWithUrl:(NSString *)url extraParam:(NSDictionary *)extraParam;

/**
 *@brief 根据URL地址获取对应Controller
 *
 *@param url URL地址
 *@param extraParam 额外的无法通过URL地址传入的参数
 *@param handle 页面回调
 *@return UIViewController 原生页面
 */
- (UIViewController *)controllerWithUrl:(NSString *)url extraParam:(NSDictionary *)extraParam handle:(LYRouteBackHandle)handle;

/**
 *@brief 根据URL push controller
 *
 *@param url URL地址
 */
- (void)pushPageWithUrl:(NSString *)url;

/**
 *@brief 根据URL push controller
 *
 *@param url URL地址
 *@param extraParam 对象类参数
 */
- (void)pushPageWithUrl:(NSString *)url extraParam:(NSDictionary *)extraParam;

/**
 *@brief 根据URL push controller
 *
 *@param url URL地址
 *@param extraParam 对象类参数
 *@param handle 页面返回对象回调
 */
- (void)pushPageWithUrl:(NSString *)url extraParam:(NSDictionary *)extraParam handle:(LYRouteBackHandle)handle;

/**
 *@brief 根据URL push controller
 *
 *@param url URL地址
 *@param extraParam 对象类参数
 *@param fromController 指定从哪个controllerpush
 *@param handle 页面返回对象回调
 */
- (void)pushPageWithUrl:(NSString *)url extraParam:(NSDictionary *)extraParam fromController:(UIViewController *)fromController handle:(LYRouteBackHandle)handle;


/**
 *@brief 根据URL push controller并替换指定的controller
 *
 *@param url URL地址
 *@param idx 可指定所以 -1为替换前一个
 *@param extraParam 对象类参数
 *@param fromController 指定从哪个controllerpush
 *@param handle 页面返回对象回调
 */
- (void)replaceWithUrl:(NSString *)url replaceIdx:(NSInteger)idx extraParam:(NSDictionary *)extraParam fromController:(UIViewController *)fromController handle:(LYRouteBackHandle)handle;

/**
 *@brief 根据URL present controller
 *
 *@param url URL地址
 *@param navCtrl 顶部导航栏
 *@param complation 结束回调
 */
- (void)presentPageWithUrl:(NSString *)url navigationCtrl:(UIViewController *)navCtrl complation:(void(^)(void))complation;

/**
 *@brief 根据URL present controller(带动画)
 *
 *@param url URL地址
 *@param extraParam 对象类参数
 *@param navCtrl 顶部导航栏
 *@param complation 结束回调
 */
- (void)presentPageWithUrl:(NSString *)url extraParam:(NSDictionary *)extraParam navigationCtrl:(UIViewController *)navCtrl complation:(void(^)(void))complation;

/**
 *@brief 根据URL present controller
 *
 *@param url URL地址
 *@param extraParam 对象类参数
 *@param navCtrl 顶部导航栏
 *@param animated 是否显示动画
 *@param complation 结束回调
 */
- (void)presentPageWithUrl:(NSString *)url extraParam:(NSDictionary *)extraParam navigationCtrl:(UIViewController *)navCtrl animated:(BOOL)animated complation:(void(^)(void))complation;

/**
 *@brief 根据URL present controller
 *
 *@param url URL地址
 *@param extraParam 对象类参数
 *@param navCtrl 顶部导航栏
 *@param animated 是否显示动画
 *@param complation 结束回调
 *@param handle 参数回调
 */
- (void)presentPageWithUrl:(NSString *)url extraParam:(NSDictionary *)extraParam navigationCtrl:(UIViewController *)navCtrl animated:(BOOL)animated complation:(void(^)(void))complation handle:(LYRouteBackHandle)handle;

/**
 *@brief 根据URL present controller
 *
 *@param url URL地址
 *@param extraParam 对象类参数
 *@param navCtrl 顶部导航栏
 *@param fromController 从哪个试图展示
 *@param animated 是否显示动画
 *@param complation 结束回调
 *@param handle 参数回调
 */
- (void)presentPageWithUrl:(NSString *)url extraParam:(NSDictionary *)extraParam navigationCtrl:(UIViewController *)navCtrl fromController:(UIViewController *)fromController animated:(BOOL)animated complation:(void(^)(void))complation handle:(LYRouteBackHandle)handle;

/**
 *@brief 返回指定索引视图(如果索引不存在则直接退回根视图)
 *
 *@param idx 页面索引
 */
- (void)popToViewControllerWithIdx:(NSInteger)idx;

/**
 *@brief 返回指定索引视图(如果索引不存在则直接退回根视图)
 *
 *@param idx 页面索引
 *@param animated 是否显示动画
 */
- (void)popToViewControllerWithIdx:(NSInteger)idx animated:(BOOL)animated;

/**
 *@brief 返回根视图视图
 */
- (void)popToRootController;

/**
 *@brief 返回根视图视图(是否显示动画)
 *
 *@param animated 是否显示动画
 */
- (void)popToRootControllerWithAnimated:(BOOL)animated;

/**
 *@brief 返回上一个视图
 */
- (void)popPrviewViewController;

/**
 *@brief 返回上一个视图(是否显示动画)
 *
 *@param animated 是否显示动画
 */
- (void)popPrviewViewControllerWithAnimated:(BOOL)animated;

/**
 *@brief 返回指定索引视图(如果索引不存在则直接退回前一个视图)
 *
 *@param idx 页面索引
 */
- (void)popToViewControllerFailToPrviewViewControllerWithIdx:(NSInteger)idx;

/**
 *@brief 返回指定索引视图(如果索引不存在则直接退回前一个视图， 是否带动画)
 *
 *@param idx 页面索引
 *@param animated 是否显示动画
 */
- (void)popToViewControllerFailToPrviewViewControllerWithIdx:(NSInteger)idx animated:(BOOL)animated;

/**
 *@brief 退出模态视图
 */
- (void)dismissViewController:(void(^)(void))complation;

/**
 *@brief 退出模态视图
 *
 *@param animated 是否显示动画
 *@param complation 结束回调
 */
- (void)dismissViewControllerAnimated:(BOOL)animated complation:(void(^)(void))complation;

/**
 *@brief 设置路由未找到错误页面
 *
 *@param viewController 错误页面
 */
- (void)setUrlNotFoundController:(UIViewController *)viewController;

@end
